﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufItem.h"
#include "GnufInfo.h"
/// \file GnufTag.h

namespace gnuf {
    class QtTag;
    class TagPad;
    /// \brief 标签
    class GNUF_BASE_EXPORT Tag : public ItemWith<QtTag>
    {
        friend class TagPad;
        CANNOT_COPY_OR_ASSIGN(Tag);
    public:
        static const EItemType Type;
        Tag(TagPad* parent);
        ~Tag() { disconnectFromQtItem(); }

        bool isSelected() const { return m_bIsSelected; }

        /// \brief 关闭Tag，即设置Tag为非激活状态
        void close();

        void assignInfo(const Info& info);

        /// \return 返回改Tag的标题，如果没有，返回一个空的wstring
        const std::wstring& caption() const;

    protected:
        // inherit from ItemWith
        void onPostVisibilityChanged() override;
        void onDisconnectFromMyQtItem() override;
        void onPostInfoChanged() override;
        void onPostAppearanceSettingChanged() override;
        void onPostAbilityChanged() override;
    private:

        /// \brief 设置QtTag的激活属性
        /// \param selected 是否激活
        /// \param anyway 无视diff的过程，强制设置激活属性
        /// \note 这个接口暂时不希望产品端获取，产品端应该通过TagPad::selecteItem()来设置标签的状态
        bool setSelected(bool selected, bool anyway = false);
        gcmp::OwnerPtr<Info> m_tagInfo;
        bool m_bIsClosable;
        bool m_bIsSelected;
    };
}
